#ifndef __LIB_GUI_LABEL_H
#define __LIB_GUI_LABEL_H 

#include<stddef.h>
#include<stdio.h>
#include"gui_spirit.h"
#include"gui_color.h"

#define gui_label_t gui_spirit_t

static  gui_spirit_t *gui_label_create(char *text)
{
    gui_spirit_t *spirit=gui_spirit_create(0,0,0,0);
    if(!spirit)
        return NULL;
    spirit->style.background_color=GUI_WHITE;
    spirit->style.font_color=GUI_BLACK;
    spirit->style.font_align=GUI_ALIGN_CENTER;
    spirit->mulline_support=0;
    gui_spirit_set_text(spirit,text);
    gui_spirit_set_type(spirit,GUI_SPIRIT_TYPE_LABEL);
    gui_spirit_auto_size(spirit);
    return spirit;
}

//return label text length
static  int gui_label_length(gui_spirit_t *label)
{
    if(!label)
        return -1;
    if(!label->text)
        return -1;
    return strlen(label->text);
}

//return label width
static  int gui_label_width(gui_spirit_t *label)
{
    if(!label)
        return -1;
    return strlen(label->text)*gui_text_char_width();
}

//update label show text context
static int gui_label_set_text(gui_spirit_t *label,char *text,int len)
{
    if(!label)
        return -1;
    gui_spirit_hide(label);
    gui_spirit_set_text(label,text);
    gui_spirit_auto_size(label);
    return 0;
}

static int gui_label_set_background_color(gui_spirit_t *label,gui_color_t background_color)
{
    if(!label)
        return -1;
    label->style.background_color=background_color;
    gui_spirit_show(label);
    return 0;
}

static int gui_label_set_color(gui_spirit_t *label,gui_color_t color)
{
    if(!label)
        return -1;
    label->style.font_color=color;
    gui_spirit_show(label);
    return 0;
}

static char *gui_label_get_text(gui_spirit_t *label)
{
    if(!label)
        return NULL;
    return label->text;
}

static  void gui_label_set_multiline(gui_spirit_t *label,uint8_t mul_line)
{
    if(!label)
        return;
    if(mul_line)
        label->mulline_support=1;
    else 
        label->mulline_support=0;
}

#endif 